<?php
$uploaddir = '/var/www/html/socket/socket/app/public/images/message/';
// $site_url = 'http://socket.test/socket/app/';
$site_url = 'http://10.3.141.169/';
$file_name = basename($_FILES['file']['name']);
$uploadfile = $uploaddir . $file_name;
// echo $uploadfile;
// echo '<pre>';
if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {
	$arr = explode('.', $file_name);
	$ext = '.'.end($arr);
	$new_name = uniqid().time().$ext;
    $res = rename($uploadfile,$uploaddir.$new_name);
    if ($res) {
    	$src = $site_url.'public/images/message/'.$new_name;
    	echo json_encode(['code' => 0, 'msg' => 'success', 'data' => ['src' => $src]]);
    }else {
    	echo json_encode(['code' => 2, 'msg' => '', 'data' => '']);
    }
} else {
    echo json_encode(['code' => 2, 'msg' => '', 'data' => '']);
}

